package repository

import (
	"github.com/gofiber/fiber/v2"
	"gorm.io/gorm"
	"guns-excel/internal/app/model"
)

// 增加规则
func AddRule(ctx *fiber.Ctx, rule *model.Rule, db *gorm.DB) error {
	return db.Table("rule").Create(&rule).Error
}

// 根据
func GetRuleByModelExcelId(ctx *fiber.Ctx, ruleId string, db *gorm.DB) (*model.Rule, error) {
	rule := new(model.Rule)
	if err := db.Table("rule").Where("is_del = ?", 0).Where("model_excel_id = ?", ruleId).First(&rule).Error; err != nil {
		return nil, err
	}
	return rule, nil
}
